﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：WF_STEPROLE实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class WF_STEPROLE
    {
        private decimal m_dec_i_buzhouid;

        private decimal? m_dec_i_iszhandian;

        private decimal m_dec_i_jiaoseid;

        private decimal m_dec_i_liuchengid;

        private decimal m_dec_id;

        /// <summary>
        ///     自增量ID
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     步骤ID
        /// </summary>
        public decimal I_BUZHOUID
        {
            get { return m_dec_i_buzhouid; }
            set { m_dec_i_buzhouid = value; }
        }

        /// <summary>
        ///     流程ID
        /// </summary>
        public decimal I_LIUCHENGID
        {
            get { return m_dec_i_liuchengid; }
            set { m_dec_i_liuchengid = value; }
        }

        /// <summary>
        ///     角色ID
        /// </summary>
        public decimal I_JIAOSEID
        {
            get { return m_dec_i_jiaoseid; }
            set { m_dec_i_jiaoseid = value; }
        }

        /// <summary>
        ///     是否需要和站点关联
        /// </summary>
        public decimal? I_ISZHANDIAN
        {
            get { return m_dec_i_iszhandian; }
            set { m_dec_i_iszhandian = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class WF_STEPROLEProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public WF_STEPROLEProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据WF_STEPROLE实体添加或者修改WF_STEPROLE信息
        /// </summary>
        public bool InsertOrUpdate(WF_STEPROLE WF_STEPROLE, OracleTransaction Transaction)
        {
            if (WF_STEPROLE.ID == 0)
                InsertWF_STEPROLE(WF_STEPROLE, Transaction);
            else
                UpdateWF_STEPROLE(WF_STEPROLE, Transaction);
            return WF_STEPROLE.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_STEPROLE实体添加或修改WF_STEPROLE信息
        /// </summary>
        public bool InsertOrUpdate(WF_STEPROLE WF_STEPROLE)
        {
            return InsertOrUpdate(WF_STEPROLE, null);
        }


        /// <summary>
        ///     根据WF_STEPROLE主键删除WF_STEPROLE信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteWF_STEPROLE(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_STEPROLE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_STEPROLE主键删除WF_STEPROLE信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteWF_STEPROLE(decimal ID)
        {
            return DeleteWF_STEPROLE(ID, null);
        }

        /// <summary>
        ///     根据条件删除WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_STEPROLEsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_STEPROLEsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_STEPROLEsDynamic(string WhereClause)
        {
            return DeleteWF_STEPROLEsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据WF_STEPROLE主键选择WF_STEPROLE信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEPROLE信息</returns>
        public WF_STEPROLE SelectWF_STEPROLE(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPROLE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var WF_STEPROLE = PopulateWF_STEPROLE(rd);
                rd.Close();
                return WF_STEPROLE;
            }
            return null;
        }

        /// <summary>
        ///     根据WF_STEPROLE主键选择WF_STEPROLE信息
        /// </summary>
        /// <returns>WF_STEPROLE信息</returns>
        public WF_STEPROLE SelectWF_STEPROLE(decimal ID)
        {
            return SelectWF_STEPROLE(ID, null);
        }

        /// <summary>
        ///     选择所有WF_STEPROLE信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPROLEsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有WF_STEPROLE信息
        /// </summary>
        /// <returns>所有WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsAll()
        {
            return SelectWF_STEPROLEsAll(null);
        }

        /// <summary>
        ///     根据条件选择WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPROLEsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectWF_STEPROLEsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_STEPROLEsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_STEPROLE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>WF_STEPROLE信息</returns>
        public DataTable SelectWF_STEPROLEsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectWF_STEPROLEsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新WF_STEPROLE字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_STEPROLEsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdWF_STEPROLEDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新WF_STEPROLE字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_STEPROLEsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateWF_STEPROLEsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertWF_STEPROLE(WF_STEPROLE WF_STEPROLE, OracleTransaction Transaction)
        {
            var spName = "CS_InsWF_STEPROLE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_STEPROLE.I_BUZHOUID;
            storedParams[1].Value = WF_STEPROLE.I_LIUCHENGID;
            storedParams[2].Value = WF_STEPROLE.I_JIAOSEID;
            storedParams[3].Value = WF_STEPROLE.I_ISZHANDIAN;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            WF_STEPROLE.ID = Convert.ToInt32(storedParams[4].Value);
            return result;
        }

        private bool UpdateWF_STEPROLE(WF_STEPROLE WF_STEPROLE, OracleTransaction Transaction)
        {
            var spName = "CS_UpdWF_STEPROLE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_STEPROLE.I_BUZHOUID;
            storedParams[1].Value = WF_STEPROLE.I_LIUCHENGID;
            storedParams[2].Value = WF_STEPROLE.I_JIAOSEID;
            storedParams[3].Value = WF_STEPROLE.I_ISZHANDIAN;
            storedParams[4].Value = WF_STEPROLE.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private WF_STEPROLE PopulateWF_STEPROLE(IDataReader dr)
        {
            var WF_STEPROLE = new WF_STEPROLE();
            WF_STEPROLE.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            WF_STEPROLE.I_BUZHOUID = dr["I_BUZHOUID"] == DBNull.Value ? 0 : (decimal) dr["I_BUZHOUID"];
            WF_STEPROLE.I_LIUCHENGID = dr["I_LIUCHENGID"] == DBNull.Value ? 0 : (decimal) dr["I_LIUCHENGID"];
            WF_STEPROLE.I_JIAOSEID = dr["I_JIAOSEID"] == DBNull.Value ? 0 : (decimal) dr["I_JIAOSEID"];
            WF_STEPROLE.I_ISZHANDIAN = dr["I_ISZHANDIAN"] == DBNull.Value ? null : (decimal?) dr["I_ISZHANDIAN"];
            return WF_STEPROLE;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion